package club.ljwang.wechat;

import club.ljwang.constant.MessageConstant;
import club.ljwang.entity.Result;
import club.ljwang.pojo.Setmeal;
import club.ljwang.service.SetmealService;
import club.ljwang.utils.JedisUtil;
import cn.hutool.core.lang.UUID;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.List;

/**
 * @Auther: wangl
 * @Date: 2020/3/2 19:43
 * @Description:
 */
@RestController
@RequestMapping("setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    @Autowired
    private JedisUtil jedisUtil;


    @RequestMapping("getSetmeal")
    public Result getSetMeal() {
        List<Setmeal> setmealList = setmealService.getSetMeal();
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmealList);

    }

    @RequestMapping("findById")
    public Result findById(Integer id) {
        Setmeal setmeal = setmealService.findById(id);
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }

    @RequestMapping("getToken")
    public Result getToken() {

        String uuid = UUID.randomUUID().toString();
        jedisUtil.setex(uuid, 60 * 60 * 2, uuid);
        return new Result(true, "生成Token", uuid);

    }

}
